<?php

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of SystemController
 *
 * @author mooshroom
 */

namespace Home\Controller ;

class SystemController extends \Think\Controller
{

    protected $UserLoginModel            = null ;
    protected $StudentBaseModel          = null ;
    protected $ActivityDictionaryModel   = null ;
    protected $ActivityLinkModel         = null ;
    protected $AcademyDictionaryModel    = null ;
    protected $ProfessionDictionaryModel = null ;

    function __construct ()
    {
        parent::__construct () ;
        $this->UserLoginModel            = new \Home\Model\UserLoginModel() ;
        $this->StudentBaseModel          = new \Home\Model\StudentBaseModel() ;
        $this->ActivityDictionaryModel   = new \Home\Model\ActivityDictionaryModel() ;
        $this->ActivityLinkModel         = new \Home\Model\UserActivityLinkModel() ;
        $this->AcademyDictionaryModel    = new \Home\Model\AcademyDictionaryModel() ;
        $this->ProfessionDictionaryModel = new \Home\Model\ProfessionDictionaryModel() ;
    }

    //用户登录页面
    function login ()
    {
        $this->display () ;
    }

    //核对用户密码
    function checkUPassword ()
    {
        $UID      = I ( 'UID' , null ) ;
        $Password = I ( 'Password' , null ) ;
        $rs       = $this->UserLoginModel->checkUPassword ( $UID , $Password ) ;
        $Status   = $this->UserLoginModel->getUserStatusByUID ( $UID ) ;
        if ( $rs )
        {
            session ( 'UID' , $UID ) ;
            switch ( $Status )
            {
                case 0:
                    $this->redirect ( 'User/student_info' ) ;
                    break ;
                case 1:
                    $this->redirect ( 'admin' ) ; //对字典表操作
                    break ;
                default :
                    $this->error ( "未知操作属性" ) ;
                    break ;
            }
        }
        else
        {
            $this->error ( "用户名或密码错误" , U ( 'login' ) ) ;
        }
    }

    //修改学生基本信息
    function updateStudentBaseInfor ()
    {

        //$UID           = session ( 'UID' ) ;
        $UName         = I ( 'UName' , null ) ;
        $UIDCardNumber = I ( 'UIDCardNumber' , null ) ;
        //通过身份证号来获取出生日期
        $UserBirthday  = $Usersubstr ( $string , $start , $length ) ;
        $UEmail        = I ( 'UEmail' , null ) ;
        $UPhoneNumber  = I ( 'UPhoneNumber' , null ) ;
        $UQQ           = I ( 'UQQ' , null ) ;
        $UPicturePath  = I ( 'UPicturePath' , null ) ;
        $AcademyID     = I ( 'AcademyID' , null ) ;
        $ProfessionID  = I ( 'ProfessionID' , null ) ;
        $GradeID       = I ( 'GradeID' , null ) ;
        $ClassID       = I ( 'ClassID' , null ) ;
        if ( $this->StudentBaseModel->updateStudentBaseInfor ( $UID , $UName ,
                        $UBirthday , $UIDCardNumber , $UEmail , $UPhoneNumber ,
                        $UQQ , $UPicturePath , $AcademyID , $ProfessionID ,
                        $GradeID , $ClassID ) )
        {
            $this->success ( '修改学生基本信息成功' ) ;
        }
        else
        {
            $this->error ( '修改失败' ) ;
        }
    }

    function ajax_get_academy ()
    {
        $this->ajaxReturn ( $this->AcademyDictionaryModel->select () , 'JSON' ) ;
    }

    function ajax_get_profession ()
    {

        $this->ajaxReturn ( $this->ProfessionDictionaryModel->where ( '' ) ) ;
    }

    function ajax_get_class ()
    {

    }

}
